package com.px.user.service;

import com.px.user.model.UpTokenModel;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class CDNService {
    @Value("${px.qiniu.access-key}")
    private String qnAccessKey;

    @Value("${px.qiniu.secret-key}")
    private String qnSecretKey;

    @Value("${px.qiniu.bucket}")
    private String qnbucket;

    @Value("${px.qiniu.domain}")
    private String domain;

    public UpTokenModel qiniuUpToken() {
        Auth auth = Auth.create(qnAccessKey, qnSecretKey);
        long expireSeconds = 3600 * 7;
        return UpTokenModel.builder()
                .domain(domain)
                .token(auth.uploadToken(qnbucket, null, expireSeconds, null))
                .build();
    }
}
